import unittest, requests


class Weidu(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')

    def tearDown(self) -> None:
        print('end case')

    # 登录
    userId = None
    sessionId = None
    phone = None

    def test_Weidu_01(self):
        r1 = requests.post(url='http://10.59.9.18/small/user/v1/login',
                           json={"phone": "15535738398", "pwd": "zjj031613"})
        print(r1.json())
        # 提取userId sessionId
        Weidu.userId = r1.json()['result']['userId']
        Weidu.sessionId = r1.json()['result']['sessionId']

    # 圈子列表
    qzid = None

    def test_Weidu_02(self):
        r2 = requests.get(url='http://10.59.9.18/small/circle/v1/findCircleList',
                          headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                          params={"page": 1, 'count': 1})
        print(r2.json())
        # 提取圈子id
        Weidu.qzid = r2.json()['result'][0]['id']
        print('圈子id：', Weidu.qzid)

    # 圈子点赞

    def test_Weidu_03(self):
        r3 = requests.post(url='http://10.59.9.18/small/circle/verify/v1/addCircleGreat',
                           headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                           params={'circleId': 1})
        print(r3.json())

    # 取消点赞

    def test_Weidu_04(self):
        r5 = requests.delete(url='http://10.59.9.18/small/circle/verify/v1/cancelCircleGreat',
                             headers={'userId': str(Weidu.userId), 'sessionId': str(Weidu.sessionId)},
                             data={'circleId': str(Weidu.qzid)})
        print(r5.json())


if __name__ == '__main__':
    # 第一种方式
    unittest.main()
